package com.s64.mq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    /**
     * 根据路由Key精确匹配
     * @return
     */
 /*   @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("s64.exchange1");
    }*/
    /**
     * 根据路由Key模糊匹配
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("s64.exchange2");
    }

    /**
     * 跟路由key无关，投递消息到所有绑定的队列
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("s64.exchange3");
    }
    @Bean
    public Queue queue1() {
        return new Queue("s64.queue.order1");
    }

    @Bean
    public Queue queue2() {
        return new Queue("s64.queue.order2");
    }

    /*@Bean
    public Binding binding1() {
        return BindingBuilder.bind(queue1()).to(directExchange()).with("new");
    }

    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(queue2()).to(directExchange()).with("delete");
    }*/

   /* @Bean
    public Binding binding1() {
        return BindingBuilder.bind(queue1()).to(topicExchange()).with("#.order.#");
    }

    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(queue2()).to(topicExchange()).with("#.order.delete");
    }*/
   @Bean
   public Binding binding1() {
       return BindingBuilder.bind(queue1()).to(fanoutExchange());
   }

    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(queue2()).to(fanoutExchange());
    }
}
